/*************************************************
 * 描述: 
 *
 * File: columndelegaterouter.cpp
 * Author: shizhixin@mozihealthcare.cn
 * Date: 2025-10-21
 * Update: 
 * ************************************************/
#include "columndelegaterouter.h"

#include <QAbstractProxyModel>

ColumnDelegateRouter::ColumnDelegateRouter(QObject* parent)
	: QStyledItemDelegate(parent)
	  , m_defaultDelegate(nullptr)
{
}

void ColumnDelegateRouter::setDefaultDelegate(QStyledItemDelegate* delegate)
{
	m_defaultDelegate = delegate;
}

void ColumnDelegateRouter::setCellDelegate(int row, QStyledItemDelegate* delegate)
{
	m_cellDelegates[row] = delegate;
}

QStyledItemDelegate* ColumnDelegateRouter::cellDelegate(int row)
{
	auto it = m_cellDelegates.find(row);
	return it != m_cellDelegates.end() ? it.value() : nullptr;
}

QStyledItemDelegate* ColumnDelegateRouter::delegateForIndex(const QModelIndex& index) const
{
	if (!index.isValid())
	{
		return m_defaultDelegate;
	}
	if (auto it = m_cellDelegates.find(index.row()); it != m_cellDelegates.end()) return it.value();
	return m_defaultDelegate;
}